package pub.tbc.api.util;

import lombok.extern.slf4j.Slf4j;
import pub.tbc.toolkit.core.collect.Lists;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;


/**
 * @author tbc on 2016/12/8 15:44:13.
 */
@Slf4j
public class Banner {

    private final String DEFAULT_BANNER_FILE = getClass().getResource("/").getPath() + "banner.txt";

    private final String DEFAULT_BANNER = "" +
            "                       .::::.\n" +
            "                     .::::::::.\n" +
            "                    :::::::::::\n" +
            "                 ..:::::::::::'\n" +
            "              '::::::::::::'\n" +
            "                .::::::::::\n" +
            "           '::::::::::::::..\n" +
            "                ..::::::::::::.\n" +
            "              ``::::::::::::::::\n" +
            "               ::::``:::::::::'        .:::.\n" +
            "              ::::'   ':::::'       .::::::::.\n" +
            "            .::::'      ::::     .:::::::'::::.\n" +
            "           .:::'       :::::  .:::::::::' ':::::.\n" +
            "          .::'        :::::.:::::::::'      ':::::.\n" +
            "         .::'         ::::::::::::::'         ``::::.\n" +
            "     ...:::           ::::::::::::'              ``::.\n" +
            "    ```` ':.          ':::::::::'                  ::::..\n" +
            "                       '.:::::'                    ':'````..\n" +
            "      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
            "                美女保佑            永无BUG";

    private void print(List<String> strings) {
        strings.forEach(System.out::println);
    }

    public void print() {
        File bannerFile = new File(DEFAULT_BANNER_FILE);
        log.debug("banner : " + bannerFile + " exists: " + bannerFile.exists());

        List<String> banner;
        if (bannerFile.exists()) {
            try {
                banner = Files.readAllLines(bannerFile.toPath(), StandardCharsets.UTF_8);
//                banner = Files.readLines(bannerFile, Charset.forName("utf-8"));
            } catch (IOException e) {
                log.error(e.getMessage());
                throw new RuntimeException("读取Banner文件出错", e);
            }
        } else {
            banner = Lists.newArrayList(DEFAULT_BANNER);
        }
        print(banner);
    }


}
